/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package br.com.documentar.view;

import br.com.documentar.interfacee.InterfaceView;
import br.com.documentar.model.JanelaModel;
import br.com.documentar.util.UtilitariosCampos;
import br.com.documentar.util.setFiltroCampo;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import javax.swing.JOptionPane;

/**
 *
 * @author Santos
 */
public class JanelaView extends javax.swing.JFrame implements InterfaceView<br.com.documentar.model.JanelaModel> {

    private br.com.documentar.controller.JanelaController control = new br.com.documentar.controller.JanelaController();
    private br.com.documentar.model.JanelaModel model = control.getModel();

    /**
     * Creates new form ProdutoController
     */
    public JanelaView() {
        initComponents();
        Start();
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        tabbedPaneManutencao = new javax.swing.JTabbedPane();
        panelConsulta = new javax.swing.JPanel();
        jLabelNome = new javax.swing.JLabel();
        textFieldConsultar = new javax.swing.JTextField();
        jScrollPanelConsulta = new javax.swing.JScrollPane();
        jTableConsulta = new javax.swing.JTable();
        panelAbaACadastro = new javax.swing.JPanel();
        jScrollPaneManutencaoA = new javax.swing.JScrollPane();
        jPanelManutencaoA = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        textFieldCodigo = new javax.swing.JTextField();
        jLabel2 = new javax.swing.JLabel();
        textFieldNome = new javax.swing.JTextField();
        jLabel3 = new javax.swing.JLabel();
        comboBoxAtivo = new javax.swing.JComboBox();
        panelAbaRelatorio = new javax.swing.JPanel();
        toolBarManutencao = new javax.swing.JToolBar();
        buttonConsultar = new javax.swing.JButton();
        buttonNovo = new javax.swing.JButton();
        buttonEditar = new javax.swing.JButton();
        buttonExcluir = new javax.swing.JButton();
        buttonCancelar = new javax.swing.JButton();
        buttonGravar = new javax.swing.JButton();
        buttonRelatorio = new javax.swing.JButton();
        buttonAnterior = new javax.swing.JButton();
        buttonProximo = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Cadastrar Janela");

        jLabelNome.setText("Pesquisar:");

        jTableConsulta.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        jTableConsulta.setAutoResizeMode(javax.swing.JTable.AUTO_RESIZE_OFF);
        jTableConsulta.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
        jTableConsulta.getTableHeader().setReorderingAllowed(false);
        jScrollPanelConsulta.setViewportView(jTableConsulta);

        javax.swing.GroupLayout panelConsultaLayout = new javax.swing.GroupLayout(panelConsulta);
        panelConsulta.setLayout(panelConsultaLayout);
        panelConsultaLayout.setHorizontalGroup(
            panelConsultaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panelConsultaLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabelNome)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(textFieldConsultar, javax.swing.GroupLayout.DEFAULT_SIZE, 523, Short.MAX_VALUE)
                .addContainerGap())
            .addComponent(jScrollPanelConsulta, javax.swing.GroupLayout.DEFAULT_SIZE, 597, Short.MAX_VALUE)
        );
        panelConsultaLayout.setVerticalGroup(
            panelConsultaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panelConsultaLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(panelConsultaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabelNome)
                    .addComponent(textFieldConsultar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addComponent(jScrollPanelConsulta, javax.swing.GroupLayout.DEFAULT_SIZE, 254, Short.MAX_VALUE))
        );

        tabbedPaneManutencao.addTab("Consulta", panelConsulta);

        jLabel1.setFont(new java.awt.Font("Arial", 0, 12)); // NOI18N
        jLabel1.setText("Código:");

        jLabel2.setFont(new java.awt.Font("Arial", 0, 12)); // NOI18N
        jLabel2.setText("Nome:");

        textFieldNome.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                textFieldNomeActionPerformed(evt);
            }
        });

        jLabel3.setText("Ativo:");

        comboBoxAtivo.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "ESCOLHER", "S - SIM", "N - NÃO" }));

        javax.swing.GroupLayout jPanelManutencaoALayout = new javax.swing.GroupLayout(jPanelManutencaoA);
        jPanelManutencaoA.setLayout(jPanelManutencaoALayout);
        jPanelManutencaoALayout.setHorizontalGroup(
            jPanelManutencaoALayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelManutencaoALayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanelManutencaoALayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel1)
                    .addComponent(jLabel2)
                    .addComponent(jLabel3))
                .addGap(117, 117, 117)
                .addGroup(jPanelManutencaoALayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(textFieldNome)
                    .addGroup(jPanelManutencaoALayout.createSequentialGroup()
                        .addGroup(jPanelManutencaoALayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(textFieldCodigo, javax.swing.GroupLayout.PREFERRED_SIZE, 159, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(comboBoxAtivo, javax.swing.GroupLayout.PREFERRED_SIZE, 160, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(0, 255, Short.MAX_VALUE)))
                .addContainerGap())
        );
        jPanelManutencaoALayout.setVerticalGroup(
            jPanelManutencaoALayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelManutencaoALayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanelManutencaoALayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(textFieldCodigo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel1))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanelManutencaoALayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(textFieldNome, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel2))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanelManutencaoALayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3)
                    .addComponent(comboBoxAtivo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jScrollPaneManutencaoA.setViewportView(jPanelManutencaoA);

        javax.swing.GroupLayout panelAbaACadastroLayout = new javax.swing.GroupLayout(panelAbaACadastro);
        panelAbaACadastro.setLayout(panelAbaACadastroLayout);
        panelAbaACadastroLayout.setHorizontalGroup(
            panelAbaACadastroLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPaneManutencaoA)
        );
        panelAbaACadastroLayout.setVerticalGroup(
            panelAbaACadastroLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPaneManutencaoA)
        );

        tabbedPaneManutencao.addTab("Pagina A", panelAbaACadastro);

        javax.swing.GroupLayout panelAbaRelatorioLayout = new javax.swing.GroupLayout(panelAbaRelatorio);
        panelAbaRelatorio.setLayout(panelAbaRelatorioLayout);
        panelAbaRelatorioLayout.setHorizontalGroup(
            panelAbaRelatorioLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 597, Short.MAX_VALUE)
        );
        panelAbaRelatorioLayout.setVerticalGroup(
            panelAbaRelatorioLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 303, Short.MAX_VALUE)
        );

        tabbedPaneManutencao.addTab("Relatório", panelAbaRelatorio);

        toolBarManutencao.setFloatable(false);
        toolBarManutencao.setRollover(true);

        buttonConsultar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/br/com/documentar/iconesManutencoes/application_form_magnify.png"))); // NOI18N
        buttonConsultar.setMnemonic('l');
        buttonConsultar.setText("Consultar");
        buttonConsultar.setFocusable(false);
        buttonConsultar.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        buttonConsultar.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        buttonConsultar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                buttonConsultarActionPerformed(evt);
            }
        });
        toolBarManutencao.add(buttonConsultar);

        buttonNovo.setIcon(new javax.swing.ImageIcon(getClass().getResource("/br/com/documentar/iconesManutencoes/application_add.png"))); // NOI18N
        buttonNovo.setMnemonic('N');
        buttonNovo.setText("Novo");
        buttonNovo.setFocusable(false);
        buttonNovo.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        buttonNovo.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        buttonNovo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                buttonNovoActionPerformed(evt);
            }
        });
        toolBarManutencao.add(buttonNovo);

        buttonEditar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/br/com/documentar/iconesManutencoes/application_edit.png"))); // NOI18N
        buttonEditar.setMnemonic('E');
        buttonEditar.setText("Editar");
        buttonEditar.setFocusable(false);
        buttonEditar.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        buttonEditar.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        buttonEditar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                buttonEditarActionPerformed(evt);
            }
        });
        toolBarManutencao.add(buttonEditar);

        buttonExcluir.setIcon(new javax.swing.ImageIcon(getClass().getResource("/br/com/documentar/iconesManutencoes/application_delete.png"))); // NOI18N
        buttonExcluir.setMnemonic('x');
        buttonExcluir.setText("Excluir");
        buttonExcluir.setFocusable(false);
        buttonExcluir.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        buttonExcluir.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        buttonExcluir.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                buttonExcluirActionPerformed(evt);
            }
        });
        toolBarManutencao.add(buttonExcluir);

        buttonCancelar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/br/com/documentar/iconesManutencoes/cancel.png"))); // NOI18N
        buttonCancelar.setMnemonic('C');
        buttonCancelar.setText("Cancelar");
        buttonCancelar.setFocusable(false);
        buttonCancelar.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        buttonCancelar.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        buttonCancelar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                buttonCancelarActionPerformed(evt);
            }
        });
        toolBarManutencao.add(buttonCancelar);

        buttonGravar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/br/com/documentar/iconesManutencoes/accept.png"))); // NOI18N
        buttonGravar.setMnemonic('a');
        buttonGravar.setText("Gravar");
        buttonGravar.setFocusable(false);
        buttonGravar.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        buttonGravar.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        buttonGravar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                buttonGravarActionPerformed(evt);
            }
        });
        toolBarManutencao.add(buttonGravar);

        buttonRelatorio.setIcon(new javax.swing.ImageIcon(getClass().getResource("/br/com/documentar/iconesManutencoes/application_side_list.png"))); // NOI18N
        buttonRelatorio.setMnemonic('R');
        buttonRelatorio.setText("Relatório");
        buttonRelatorio.setFocusable(false);
        buttonRelatorio.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        buttonRelatorio.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        buttonRelatorio.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                buttonRelatorioActionPerformed(evt);
            }
        });
        toolBarManutencao.add(buttonRelatorio);

        buttonAnterior.setIcon(new javax.swing.ImageIcon(getClass().getResource("/br/com/documentar/iconesManutencoes/arrow_left.png"))); // NOI18N
        buttonAnterior.setMnemonic('o');
        buttonAnterior.setText("Anterior");
        buttonAnterior.setFocusable(false);
        buttonAnterior.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        buttonAnterior.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        buttonAnterior.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                buttonAnteriorActionPerformed(evt);
            }
        });
        toolBarManutencao.add(buttonAnterior);

        buttonProximo.setIcon(new javax.swing.ImageIcon(getClass().getResource("/br/com/documentar/iconesManutencoes/arrow_right.png"))); // NOI18N
        buttonProximo.setMnemonic('m');
        buttonProximo.setText("Próximo");
        buttonProximo.setFocusable(false);
        buttonProximo.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        buttonProximo.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        buttonProximo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                buttonProximoActionPerformed(evt);
            }
        });
        toolBarManutencao.add(buttonProximo);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(tabbedPaneManutencao)
            .addComponent(toolBarManutencao, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(toolBarManutencao, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(tabbedPaneManutencao))
        );

        pack();
        setLocationRelativeTo(null);
    }// </editor-fold>//GEN-END:initComponents

    private void buttonConsultarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonConsultarActionPerformed
        Consultar();
    }//GEN-LAST:event_buttonConsultarActionPerformed

    private void buttonNovoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonNovoActionPerformed
        CarregarNovoDados();
    }//GEN-LAST:event_buttonNovoActionPerformed

    private void buttonEditarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonEditarActionPerformed
        CarregarEditarDados();
    }//GEN-LAST:event_buttonEditarActionPerformed

    private void buttonExcluirActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonExcluirActionPerformed
        CarregarExcluirDados();
    }//GEN-LAST:event_buttonExcluirActionPerformed

    private void buttonCancelarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonCancelarActionPerformed
        CancelarOperacao();
    }//GEN-LAST:event_buttonCancelarActionPerformed

    private void buttonGravarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonGravarActionPerformed
        GravarDados();
    }//GEN-LAST:event_buttonGravarActionPerformed

    private void buttonRelatorioActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonRelatorioActionPerformed
        tabbedPaneManutencao.setSelectedIndex(2);
    }//GEN-LAST:event_buttonRelatorioActionPerformed

    private void buttonAnteriorActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonAnteriorActionPerformed
        ProximaAba("Anterior");
    }//GEN-LAST:event_buttonAnteriorActionPerformed

  private void buttonProximoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonProximoActionPerformed
      ProximaAba("Proximo");
  }//GEN-LAST:event_buttonProximoActionPerformed

    private void textFieldNomeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_textFieldNomeActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_textFieldNomeActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main() {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(JanelaView.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(JanelaView.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(JanelaView.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(JanelaView.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            @Override
            public void run() {
                new JanelaView().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton buttonAnterior;
    private javax.swing.JButton buttonCancelar;
    protected javax.swing.JButton buttonConsultar;
    private javax.swing.JButton buttonEditar;
    private javax.swing.JButton buttonExcluir;
    private javax.swing.JButton buttonGravar;
    private javax.swing.JButton buttonNovo;
    private javax.swing.JButton buttonProximo;
    private javax.swing.JButton buttonRelatorio;
    private javax.swing.JComboBox comboBoxAtivo;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabelNome;
    private javax.swing.JPanel jPanelManutencaoA;
    private javax.swing.JScrollPane jScrollPaneManutencaoA;
    private javax.swing.JScrollPane jScrollPanelConsulta;
    private javax.swing.JTable jTableConsulta;
    private javax.swing.JPanel panelAbaACadastro;
    private javax.swing.JPanel panelAbaRelatorio;
    private javax.swing.JPanel panelConsulta;
    private javax.swing.JTabbedPane tabbedPaneManutencao;
    private javax.swing.JTextField textFieldCodigo;
    private javax.swing.JTextField textFieldConsultar;
    private javax.swing.JTextField textFieldNome;
    private javax.swing.JToolBar toolBarManutencao;
    // End of variables declaration//GEN-END:variables

    @Override
    public void CarregarEditarDados() {
        model.setActionScript("U");
        if (jTableConsulta.getSelectedRow() != -1) {
            JanelaModel janelaModel = model.getJanela(Integer.parseInt(jTableConsulta.getValueAt(jTableConsulta.getSelectedRow(), 0).toString()));

            textFieldCodigo.setText(String.valueOf(janelaModel.getCodigo()));
            textFieldNome.setText(janelaModel.getNome());
            comboBoxAtivo.setSelectedItem(janelaModel.getAtivo() == 'S' ? "S - SIM" : "N - NÃO");

            tabbedPaneManutencao.setSelectedIndex(1);
            textFieldNome.requestFocus();
            textFieldCodigo.setEnabled(false);
        } else {
            JOptionPane.showMessageDialog(rootPane, "Nenhuma linha selecionada");
        }
    }

    @Override
    public void CarregarNovoDados() {
        model.setActionScript("I");
        textFieldCodigo.setEnabled(false);
        tabbedPaneManutencao.setSelectedIndex(1);
        textFieldNome.requestFocus();
    }

    @Override
    public void CarregarExcluirDados() {
        if (jTableConsulta.getSelectedRow() != -1) {
            JanelaModel janelaModel = model.getJanela(Integer.parseInt(jTableConsulta.getValueAt(jTableConsulta.getSelectedRow(), 0).toString()));
            janelaModel.setActionScript("D");
            control.setDados(janelaModel);
        } else {
            JOptionPane.showMessageDialog(rootPane, "Nenhuma linha selecionada");
        }
        Consultar();
    }

    @Override
    public void GravarDados() {
        if (model.getActionScript().equals("I") || model.getActionScript().equals("U")) {
            if (ValidaCampos()) {
                CarregarVariaveis();
                if (model.getActionScript().equals("I") && model.getJanela(model.getCodigo()) != null) {
                    JOptionPane.showMessageDialog(panelConsulta, "Item já cadastrado na base de dados.");
                } else {
                    if (control.setDados(model)) {
                        Consultar();
                        LimparCampos();
                    }
                }
            }
        } else {
            JOptionPane.showMessageDialog(panelConsulta, "Você deve escolher uma ação clicando no botão Novo ou Editar.");
        }
    }

    @Override
    public void LimparCampos() {
        UtilitariosCampos.getLimpezaCampos(tabbedPaneManutencao);
    }

    @Override
    public void ProximaAba(String Movimento) {
        int a = tabbedPaneManutencao.getSelectedIndex();
        int quantidadeAba = tabbedPaneManutencao.getTabCount() - 1;
        switch (Movimento) {
            case "Anterior":
                if (a != 0) {
                    tabbedPaneManutencao.setSelectedIndex(a - 1);
                }
                break;
            case "Proximo":
                if (a != quantidadeAba) {
                    tabbedPaneManutencao.setSelectedIndex(a + 1);
                }
                break;
        }
    }

    @Override
    public void TamanhoColunaTable() {
        jTableConsulta.getColumnModel().getColumn(0).setMinWidth(10);//código
        jTableConsulta.getColumnModel().getColumn(0).setPreferredWidth(60);
        jTableConsulta.getColumnModel().getColumn(0).setMaxWidth(100);

        jTableConsulta.getColumnModel().getColumn(1).setMinWidth(30);//nome
        jTableConsulta.getColumnModel().getColumn(1).setPreferredWidth(270);
        jTableConsulta.getColumnModel().getColumn(1).setMaxWidth(670);

        jTableConsulta.getColumnModel().getColumn(2).setMinWidth(30);//ativo
        jTableConsulta.getColumnModel().getColumn(2).setPreferredWidth(60);
        jTableConsulta.getColumnModel().getColumn(2).setMaxWidth(100);

    }

    @Override
    public void Consultar() {
        model.setActionScript("C");
        jTableConsulta.setModel(control.getDadosTableModel(model));
        tabbedPaneManutencao.setSelectedIndex(0);
        textFieldConsultar.requestFocus();
        TamanhoColunaTable();
    }

    @Override
    public void CommitCampos() {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    public void CancelarOperacao() {
        LimparCampos();
        Consultar();
    }

    @Override
    public void CarregarVariaveis() {
        model.setCodigo(UtilitariosCampos.getIntegerText(textFieldCodigo));
        model.setNome(textFieldNome.getText().toString());
        model.setAtivo(comboBoxAtivo.getSelectedItem().toString().charAt(0));
    }

    /**
     * Metodo responsável por reescrever o metodo que escuta o textField de
     * pesquisa
     */
    KeyAdapter pesquisaDados = new KeyAdapter() {
        @Override
        public void keyPressed(KeyEvent e) {

            switch (e.getKeyCode()) {
                case KeyEvent.VK_ENTER://Botão Enter
                    model.setNome(textFieldConsultar.getText());
                    model.setActionScript("P");
                    jTableConsulta.setModel(control.getDadosTableModel(model));
                    TamanhoColunaTable();
                    break;
            }
        }
    };

    @Override
    public void InicializarListener() {
        textFieldConsultar.addKeyListener(pesquisaDados);
    }

    @Override
    public void Start() {
        Consultar();
        InicializarListener();
        setExtendedState(MAXIMIZED_BOTH);
        model.setNomeTela(getTitle());
        setFiltroCampo();
    }

    @Override
    public boolean ValidaCampos() {
        if (!UtilitariosCampos.getValidarCampos(jPanelManutencaoA)) {
            tabbedPaneManutencao.setSelectedIndex(1);
            return false;
        } else {
            return true;
        }
    }

    @Override
    public void CarregarDadosComboBox(JanelaModel model, String actionScript) {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    public void setFiltroCampo() {
        textFieldConsultar.setDocument(new setFiltroCampo(50, "LetraNumeroRealEspaco"));
        textFieldNome.setDocument(new setFiltroCampo(50, "Texto", 'P'));
    }
}
